package ferhrosa.android;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class TesteAndroidActivity extends Activity {
    
    private List<ListViewItem> items = new ArrayList();
    private static ListViewAdapter adapter = null;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Init items
        items.add(new ListViewItem("SCAN", "Scan a barcode", ListViewItem.SCAN));
        items.add(new ListViewItem("SEARCH", "Search for a product",
                ListViewItem.SEARCH));
        items.add(new ListViewItem("HELP", "How to use this app", ListViewItem.HELP));

        // Set adapter basing on template 1
        adapter = new ListViewAdapter(this, items, ListViewAdapter.TPL_1);

        ListView mainMenu = (ListView) findViewById(R.id.menu);
        mainMenu.setAdapter(adapter);
        mainMenu.setTextFilterEnabled(true);

        mainMenu.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long arg3) {
                ListViewItem selectedMenuItem = items.get((int) position);
                int selectedMenuItemType = selectedMenuItem.getType();

                switch (selectedMenuItemType) {
                case ListViewItem.SCAN:
                    // Handle method...
                    break;
                case ListViewItem.SEARCH:
                    // Handle method...
                    break;
                case ListViewItem.HELP:
                    // Handle method...
                    break;
                }
            }
        });
    }
}